import pymysql

conn = None
cursor = None
try:
    conn = pymysql.connect(host='192.168.174.132', port=3306, user='root', password='iTest_2022_mysql', database='test_db', charset='utf8')
    cursor = conn.cursor()
    cursor.execute("select t.Tname from teacher t where t.CId is null;")
    res = cursor.fetchone()
    print("没有授课的老师是:", res[0])
    cursor.execute("select t.Tname from teacher t ,course c where t.CId = c.CId and c.Cname = '语文';")
    res = cursor.fetchall()
    print("所有语文老师:", res[0][0], res[1][0], res[2][0])
    cursor.execute("select c.Cname from teacher t inner join course c on t.CId = c.CId where t.CId is not null group by t.CId order by count(1) limit 1;")
    res = cursor.fetchone()
    print("授课老师最少的学科:", res[0])
except Exception as err:
    print('错误信息:', err)
    pass
finally:
    cursor.close()
    conn.close()


# (1, 'Alice', 25, 'alice@example.com')
# (2, 'Bob', 30, 'bob@example.com')
# (3, 'Carol', 28, 'carol@example.com')

# ID: 1, Name: Alice, Age: 25, Email: alice@example.com
# ID: 2, Name: Bob, Age: 30, Email: bob@example.com
# ID: 3, Name: Carol, Age: 28, Email: carol@example.com